Friend Class DBConfig_Factory
    Inherits DBBase

    Public Function GetConfigFromName(ByVal sName As String) As Config
        Dim oConfig As Config = Nothing

        Dim sSQL As String = "select"
        sSQL = sSQL & "     [ID]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     [Configuration]"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [Name]=" & ValueToDBValue(sName)

        Dim oValue As Object = MyBase.ExecuteScalar(sSQL)
        If Not oValue Is Nothing Then
            oConfig = New Config(Val(oValue))
            oConfig.Load()
        End If

        Return oConfig
    End Function

    Public Function GetValueFromName(ByVal sName As String) As String
        Dim sSQL As String = "select"
        sSQL = sSQL & "     [Value]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     [Configuration]"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [Name]=" & ValueToDBValue(sName)

        Dim oValue As Object = MyBase.ExecuteScalar(sSQL)

        If oValue > "" Then
            Return oValue.ToString
        Else
            Return ""
        End If
    End Function

    Public Sub SetValueFromName( _
                        ByVal sName As String, _
                        ByVal sValue As String)

        Dim sSQL As String = "update [Configuration] set"
        sSQL = sSQL & "     [Value]=" & ValueToDBValue(sValue)
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [Name]=" & ValueToDBValue(sName)

        Dim iCount As Integer = MyBase.ExecuteNonQuery(sSQL)

        If iCount = 0 Then
            Dim oConfig As New Config
            oConfig.Name = sName
            oConfig.Value = sValue
            oConfig.Save()
        End If
    End Sub
End Class
